<template>
    <div class="user">
        <div class="user-style">
            <img v-if="userData.photo" class="photo" alt="用户头像" :src="returnImgUrl">
            <div v-else class="photo" style="display: flex;align-items: center;justify-content: center;border: 1px solid gray"><span>暂无头像</span></div>
            <div class="name">
                <span>{{userData.userName}}</span>
                <img v-if="userData.sex === '女'"  class="sex" src="@/assets/sex-girl.png"/>
                <img v-else class="sex" src="@/assets/sex-boy.png"/>
            </div>
            <div class="info">
                <el-row class="info-row">
                    <el-col :span="6" class="info-col-1">角色</el-col>
                    <el-col :span="18" class="info-col-2">{{userData.roleId | RoleNameFilter}}</el-col>
                </el-row>
                <el-row class="info-row">
                    <el-col :span="6" class="info-col-1">账户</el-col>
                    <el-col :span="18" class="info-col-2">{{userData.account}}</el-col>
                </el-row>
                <el-row class="info-row">
                    <el-col :span="6" class="info-col-1">电话</el-col>
                    <el-col :span="18" class="info-col-2">{{userData.phone}}</el-col>
                </el-row>
                <el-row class="info-row">
                    <el-button type="normal" size="small" icon="el-icon-edit" @click="editUser"></el-button>
                    <el-button type="normal" size="small" icon="el-icon-delete" @click="deleteUser"></el-button>
                </el-row>
            </div>
        </div>
    </div>
</template>

<script>
    import Filter from '../utils/filter.js'
    import Config from '../config'
    export default {
        name: "UserManager",
        props:{
          userData:{
              type:Object,
              default:function () {
                return this.user;
              }
          }
        },
        data(){
            return{
                imgUrl:"",
                user:{
                    photo:"@/assets/1.png",
                    account:"admin",
                    username:"张三",
                    roleId:1,
                    sex:"女",
                    phone:13344455
                }
            }
        },
        methods:{
            editUser(){
                this.$emit("edit-user",this.userData)
            },
            deleteUser(){
                this.$emit("delete-user",this.userData.id);
            }
        },
        computed:{
            returnImgUrl:function () {
                return Config.domain+this.userData.photo;
            }
        },
        filters:{
            RoleNameFilter:function (data) {
               return Filter.RoleFilter(data);
            }
        }
    }
</script>

<style scoped lang="less">
    .user{
        width: 300px;
        height: 431px;
        .user-style{
            width: 100%;
            height: 100%;
            background-color: #7fa1be;
            font-size: 16px;
            display: flex;
            flex-direction: column;
            align-items: center;
            /*border-radius: 10px;*/
            box-shadow: darkgrey 10px 10px 30px 5px;
            cursor: pointer;
            .photo{
                width: 150px;
                height: 150px;
                border-radius: 50%;
                margin-top: 10px;
            }
            .name{
                height: 70px;
                line-height: 70px;
                font-size: 20px;
                letter-spacing: 10px;
                .sex{
                    position: relative;
                    width: 24px;
                    height: 24px;
                }
            }
            .info{
                width: 100%;
                height: 100%;
                display: flex;
                flex-direction: column;
                justify-content: space-around;
                .info-row{
                    width: 100%;
                    text-align: center;
                    padding: 0 20px;
                    color: white;
                    .info-col-1{
                        background-color: #646464;
                        height: 30px;
                        line-height: 30px;
                    }
                    .info-col-2{
                        background-color: #909399;
                        height: 30px;
                        line-height: 30px
                    }
                }
            }
            &:hover{
                background-color: #75afbd;
                .name{
                    span{
                        font-weight: 600;
                    }
                }
            }
        }

    }
</style>